<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>后台管理系统</title>
        <meta name="author" content="BaiYY"/>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
        <meta name="renderer" content="webkit">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/pages.css"/>
        <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/pages.js"></script>
    </head>
<body>
    <div class="right-sidebar" style="max-width: 1200px;">
        <ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
            <li role="presentation"><a href="onLinePay.html">在线充值</a></li>
            <li role="presentation" class="active"><a href="onLinePayDetail.html">在线充值查询</a></li>
        </ul>
        <div>
            <div class="input-group col-md-12" style="margin: 10px auto;">
                <input type="number" min="0" class="form-control" placeholder="请输入游戏ID" name="user_id" id="user_id">
                <span class="input-group-addon" id="cbtn">查询</span>
            </div>
            <section class="table-responsive">
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>游戏ID</th>
                        <th>支付金额</th>
                        <th>支付状态</th>
                        <th>商品编号</th>
                        <th>支付时间</th>
                    </tr>
                    </thead>
                    <tbody id="dataList"></tbody>
                </table>
            </section>
            <div id="playerPage">
                <a href="javascript:void(0)" id="prev">上一页</a>
                <a href="javascript:void(0)" id="page"></a>
                <a href="javascript:void(0)" id="next">下一页</a>
                <span>一共</span>
                <a href="javascript:void(0)" id="totalPage"></a>
                <span>页</span>
            </div>
            <div style="margin: 10px auto;display: none;" id="exports" ><a onclick="handel(this)" class="btn btn-primary">全部导出excel</a></div>
        </div>
    </div>
    <script type="text/javascript">
        $("#user_id").blur(function () {
            var user_id = $.trim($("#user_id").val());
            if(user_id != '') {
                $.ajax({
                    type:"get",
                    url:"{:U('Admin/Login/checkedUidState')}?user_id=" + user_id,
                    success: function (data) {
                        if(data == 'unexist') {
                            alert("此UID无效！");
                            window.location.href="{:U('Admin/Main/onLinePayDetail')}";
                            return false;
                        }
                    }
                })
            }
        })
        $("#cbtn").on("click",function () {
            var uid = $.trim($("#user_id").val());
            if(uid == '' || uid == null) {
                alert("请输入要查询的游戏ID");
                window.location.href="{:U('Admin/Main/onLinePayDetail')}";
                return false;
            }
            $.ajax({
                type:'get',
                url:"{:U('Admin/Main/onLinePayList')}?uid="+uid,
                success:function (data) {
                    var count = Math.ceil(data.count/10);
                    console.log(data);
                    if(data != 'error' && data.arr.length > 0) {
                        var str = '';
                        var state = '';
                       for(var i=0;i<data.arr.length;++i) {
                           if(data.arr[i].status == 0) {
                               state = '失败';
                           }else if(data.arr[i].status == 1) {
                               state = '成功';
                           }
                           str += "<tr><td><input type='hidden' value='"+data.arr[i].time+"'/>"+data.arr[i].uid+"</td><td>"+data.arr[i].money+"</td><td>"+state+"</td><td>"+data.arr[i].item+"</td><td class='atime'>"+getLocalTime(data.arr[i].time/1000)+"</td><td>";
                           $("#exports").show();
                       }
                       $("#dataList").html(str);
                        $("#totalPage").text(count);
                        $("#page").text(1);
                    }else{
                        $("#dataList").html("暂时没有数据");
                    }
                }
            })
        });
        $("#prev").on("click",function (ev) {
            var uid = $.trim($("#user_id").val());
            var page = $.trim($("#page").text());
            var start = $("#dataList tr:first").find("input").val();

            var action = -1;
            if(page == 1) {
                page = 1;
                return false;
            }else if($("#page").text() > 1) {
                page = page - 1;
            }
            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/onLinePayList')}",
                dataType:"text",
                async:false,
                data:{"start":start,"action":action,"page":page,"uid":uid},
                success: function (data) {
                    console.log(data);
                    data = JSON.parse(data);
                    if(data != 'error') {
                        var str = '';
                        var state = '';
                        for(var i=0;i<data.arr.length;++i) {
                            if(data.arr[i].status == 0) {
                                state = '失败';
                            }else if(data.arr[i].status == 1) {
                                state = '成功';
                            }
                            str += "<tr><td><input type='hidden' value='"+data.arr[i].time+"'/>"+data.arr[i].uid+"</td><td>"+data.arr[i].money+"</td><td>"+state+"</td><td>"+data.arr[i].item+"</td><td class='atime' data-time='"+data.arr[i].time+"'>"+getLocalTime(data.arr[i].time/1000)+"</td></tr>";
                        }
                        $("#dataList").html(str);
                        $("#page").text(page);
                    }else{
                        $("#dataList").html("暂时没有数据");
                    }
                }
            })
        })

        $("#next").on("click",function (ev) {
            var uid = $.trim($("#user_id").val());
            var page = $.trim($("#page").text());
            var start = $("#dataList tr:last").find("input").val();
//            console.log(start);
            var action = 1;

            page = ++page;
            var totalPage = $.trim($("#totalPage").text())/1;
            if(page > totalPage) {
                return false;
            }
            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/onLinePayList')}",
                async:false,
                dataType:"text",
                data:{"start":start,"action":action,"page":page,"uid":uid},
                success: function (data) {
                    console.log(data);
                    data = JSON.parse(data);
                    if(data != 'error') {
                        var str = '';
                        var state = '';
                        for(var i=0;i<data.arr.length;++i) {
                            if(data.arr[i].status == 0) {
                                state = '失败';
                            }else if(data.arr[i].status == 1) {
                                state = '成功';
                            }
                            str += "<tr><td><input type='hidden' value='"+data.arr[i].time+"'/>"+data.arr[i].uid+"</td><td>"+data.arr[i].money+"</td><td>"+state+"</td><td>"+data.arr[i].item+"</td><td class='atime'>"+getLocalTime(data.arr[i].time/1000)+"</td></tr>";
                        }
                        $("#dataList").html(str);
                        $("#page").text(page);
                    }else{
                        $("#dataList").html("暂时没有数据");
                    }
                },
                error:function (err) {
                    console.log(111);
                    console.log(err);
                }
            })
        })
        function handel(This) {
            var uid = $.trim($("#user_id").val());
            $(This).attr("href","{:U('Admin/Main/expEvePlayer')}?uid="+uid);
        }
    </script>
</body>
</html>